package com.memorywords.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.autoconfigure.PageHelperProperties;
import com.github.pagehelper.autoconfigure.PageHelperStandardProperties;
import com.memorywords.mapper.UserMapper;
import com.memorywords.mapper.WordMapper;
import com.memorywords.pojo.PageResult;
import com.memorywords.pojo.Word;
import com.memorywords.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WordServiceImpl implements WordService {

    @Autowired
    private WordMapper wordMapper;


    @Override
    public List<Word> getNew(int progress) {
        return wordMapper.getNew(progress);
    }

    @Override
    public void mark(int userId, int wordId) {
        wordMapper.mark(userId, wordId);
    }

    @Override
    public List<Word> getOld(int userId) {
//        List<Integer> list =  wordMapper.getOld(userId);
//        return wordMapper.getWords(list);
        return wordMapper.getOld(userId);
    }

    @Override
    public void remove(int userId, int wordId) {
        wordMapper.remove(userId, wordId);
    }

    @Override
    public PageResult getAll(int userId, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        Page<Word> page = wordMapper.getAll(userId, pageNum, pageSize);

        long total = page.getTotal();
        List<Word> list = page.getResult();

        return new PageResult(total, list);
    }


}
